
#include"Protoclo.hpp"
#include"Sock.hpp"

void Usig(string proc)
{
    cout<<"Usig: "<<proc<<"server_ip server_port"<<endl;
}
int main(int argc,char * argv[])
{
    if(argc!=3)
    {
        Usig(argv[0]); exit(1);
    }
    int sock=Sock::Socket();
    Sock::Connect(sock,argv[1],atoi(argv[2]));

    request_t req;
    memset(&req,0,sizeof(req));
     cout << "Please Enter Data One# ";
    cin >> req._x;
    cout << "Please Enter Data Two# ";
    cin >> req._y;
    cout << "Please Enter operator# ";
    cin >> req._op;

    string json_string=SerializeRequest(req);//把输入的请求序列化
    ssize_t  s= write(sock,json_string.c_str(),json_string.size());

    char buffer[1024];
    s=read(sock,buffer,sizeof(buffer)-1);
    if(s>0)
    {
        response_t resp;
        buffer[s]=0;
        string str=buffer;
        DeserializeResponse(str,resp);//把server处理的数据反序列化

        cout<<"code:"<<resp._code<<endl;
        cout<<"result:"<<resp._result<<endl;
    }
    return 0;

}